# -*-coding:utf-8 -*-
"""
# File       : main_gui.py
# Time       ：2022/3/21 11:05
# Author     ：Coco
# version    ：python 3.7
"""
import sys

from PyQt5.QtCore import QSize, Qt, QDate
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QLabel, QVBoxLayout, QHBoxLayout, \
    QStatusBar, QDateEdit, QButtonGroup, QToolButton, QRadioButton, QToolBar, QGroupBox, QFormLayout, QLineEdit, \
    QGridLayout, QComboBox, QListWidget, QListWidgetItem, QListView, QSpacerItem, QSizePolicy, QProgressBar
from gui import constant
from gui.custom_widget.panel_widget import PanelWidget

OPEN_ICON_PATH = "./static/style_sheet/icons/open.png"
LE_LENGTH = 120
UNIT_LENGTH = 70


class Gui(QMainWindow):
    def __init__(self):
        super(Gui, self).__init__()
        # 读取 QSS 并设置
        with open("./static/style_sheet/origin.qss", mode='r', encoding='utf-8') as f:
            style_sheet = f.read()
        self.setStyleSheet(style_sheet)
        # 窗口标题、Logo
        self.setWindowIcon(QIcon("./static/style_sheet/icons/logo.png"))
        self.setWindowTitle("硅光测试软件")
        self._setup_ui()
        self.resize(1280, 880)

    def _setup_ui(self):
        # 工具栏
        self.tool_bar = QToolBar()

        self.tool_bar.setIconSize(QSize(35,35))
        self.tb_start = QToolButton()
        self.tb_start.setIcon(QIcon("./static/style_sheet/icons/start.png"))
        self.tb_start.setToolTip("开始测试")
        self.tb_pause = QToolButton()
        self.tb_pause.setIcon(QIcon("./static/style_sheet/icons/pause.png"))
        self.tb_pause.setToolTip("暂停测试")
        self.tb_continue = QToolButton()
        self.tb_continue.setIcon(QIcon("./static/style_sheet/icons/continue.png"))
        self.tb_continue.setToolTip("继续测试")
        self.tb_stop = QToolButton()
        self.tb_stop.setIcon(QIcon("./static/style_sheet/icons/stop.png"))
        self.tb_stop.setToolTip("停止测试")
        self.tb_save_config = QToolButton()
        self.tb_save_config.setIcon(QIcon("./static/style_sheet/icons/save_file.png"))
        self.tb_save_config.setToolTip("保存设置")
        self.tb_read_config = QToolButton()
        self.tb_read_config.setIcon(QIcon("./static/style_sheet/icons/open_file.png"))
        self.tb_read_config.setToolTip("读取设置")
        self.tb_pair_smu_dcp = QToolButton()
        self.tb_pair_smu_dcp.setIcon(QIcon("./static/style_sheet/icons/setting.png"))
        self.tb_pair_smu_dcp.setToolTip("设置DCP探针和SMU对应关系")

        self.tb_import_subdie_file = QToolButton()
        self.tb_import_subdie_file.setIcon(QIcon("./static/style_sheet/icons/import.png"))
        self.tb_import_subdie_file.setToolTip("导入SubDie文件")

        self.tb_stop_sip_tools = QToolButton()
        self.tb_stop_sip_tools.setIcon(QIcon("./static/style_sheet/icons/stop_sip.png"))
        self.tb_stop_sip_tools.setToolTip("停止SiPTools")

        self.tb_manual = QToolButton()
        self.tb_manual.setIcon(QIcon("./static/style_sheet/icons/manual.png"))
        self.tb_manual.setToolTip("手动测试LOSS_GC")
        self.tb_manual.hide()

        self.tb_delete = QToolButton()
        self.tb_delete.setIcon(QIcon("./static/style_sheet/icons/delete.png"))
        self.tb_delete.setToolTip("删除测试序列")

        self.tb_stability = QToolButton()
        self.tb_stability.setIcon(QIcon("./static/style_sheet/icons/stability.png"))
        self.tb_stability.setToolTip("稳定性测试")

        self.tb_flush_equipment = QToolButton()
        self.tb_flush_equipment.setIcon(QIcon("./static/style_sheet/icons/flush.png"))
        self.tb_flush_equipment.setEnabled(False)
        self.tb_flush_equipment.setToolTip("刷新设备状态")

        self.tb_statis = QToolButton()
        self.tb_statis.setIcon(QIcon("./static/style_sheet/icons/statistics.png"))
        self.tb_statis.setToolTip("数据分析")

        self.tb_wafer = QToolButton()
        self.tb_wafer.setIcon(QIcon("./static/style_sheet/icons/wafer.png"))
        self.tb_wafer.setToolTip("wafer设置")

        self.tool_bar.addWidget(self.tb_start)
        self.tool_bar.addWidget(self.tb_pause)
        self.tool_bar.addWidget(self.tb_continue)
        self.tool_bar.addWidget(self.tb_stop)
        self.tool_bar.addWidget(self.tb_save_config)
        self.tool_bar.addWidget(self.tb_read_config)
        self.tool_bar.addWidget(self.tb_pair_smu_dcp)
        self.tool_bar.addWidget(self.tb_import_subdie_file)
        self.tool_bar.addWidget(self.tb_stop_sip_tools)
        self.tool_bar.addWidget(self.tb_delete)
        self.tool_bar.addWidget(self.tb_manual)
        self.tool_bar.addWidget(self.tb_stability)
        self.tool_bar.addWidget(self.tb_flush_equipment)
        self.tool_bar.addWidget(self.tb_statis)
        self.tool_bar.addWidget(self.tb_wafer)
        self.tool_bar.setMovable(False)
        self.addToolBar(self.tool_bar)

        # 状态栏
        self.statusbar = QStatusBar()
        self.setStatusBar(self.statusbar)
        # 红色状态标签
        self.lb_status_title = QLabel("仪表连接状态: ")
        self.lb_status_red = QLabel()
        self.lb_status_red.setObjectName("lb_status_red")
        # 绿色状态标签
        self.lb_status_green = QLabel()
        self.lb_status_green.setObjectName("lb_status_green")

        self.statupbar = QProgressBar()
        self.statupbar.hide()
        self.statupbar.setRange(0, 100)
        self.statusbar.addPermanentWidget(self.statupbar)

        self.statusbar.addWidget(self.lb_status_title)
        self.statusbar.addWidget(self.lb_status_red)
        self.statusbar.addWidget(self.lb_status_green)
        self.lb_status_red.hide()
        self.lb_status_green.hide()

        # 主界面控件
        self.wd_main = QWidget()
        self.vl_main = QVBoxLayout(self.wd_main)

        # 测试信息输入部分
        self.wd_top = QWidget()
        self.hl_top = QHBoxLayout(self.wd_top)
        self.hl_top.setContentsMargins(0, 0, 0, 0)
        self.hl_top.setSpacing(10)

        self.gb_test_info = QGroupBox("设置基本信息")
        self.gb_test_info.setFixedSize(450, 200)
        self.fl_test_info = QFormLayout(self.gb_test_info)
        self.fl_test_info.setVerticalSpacing(5)
        self.fl_test_info.setHorizontalSpacing(20)
        self.lb_operator = QLabel("Operator")
        self.lb_operator.setObjectName("lb_operator")
        self.le_operator = QLineEdit()
        self.le_operator.setText("Operator")
        self.le_operator.setObjectName("le_operator")
        self.le_operator.setClearButtonEnabled(True)

        # Machine
        self.lb_machine = QLabel("Machine ID")
        self.lb_machine.setObjectName("lb_machine")
        self.le_machine = QLineEdit()
        self.le_machine.setText("001")
        self.le_machine.setObjectName("le_machine")
        self.le_machine.setClearButtonEnabled(True)


        self.lb_data = QLabel("Date")
        self.lb_data.setObjectName("lb_data")
        self.de_date = QDateEdit(QDate.currentDate())
        self.de_date.setDisplayFormat("yyyy-MM-dd")  # 设置日期格式
        self.de_date.setMinimumDate(QDate.currentDate().addDays(-365))  # 设置最小日期
        self.de_date.setMaximumDate(QDate.currentDate().addDays(365))  # 设置最大日期
        self.de_date.setObjectName("de_date")
        self.de_date.setCalendarPopup(True)

        self.lb_batch_num = QLabel("Vendor")
        self.lb_batch_num.setObjectName("lb_batch_num")
        self.le_batch_num = QLineEdit()
        self.le_batch_num.setText("AMF")
        self.le_batch_num.setObjectName("le_batch_num")
        self.le_batch_num.setClearButtonEnabled(True)

        # self.lb_lot_id = QLabel("Lot ID")
        # self.lb_lot_id.setObjectName("lb_lot_id")
        # self.le_lot_id = QLineEdit()
        # self.le_lot_id.setText("001")
        # self.le_lot_id.setObjectName("le_lot_id")
        # self.le_lot_id.setClearButtonEnabled(True)

        self.lb_wafer_id = QLabel("Wafer ID")
        self.lb_wafer_id.setObjectName("lb_wafer_id")
        self.le_wafer_id = QLineEdit()
        self.le_wafer_id.setText("12345")
        self.le_wafer_id.setObjectName("le_wafer_id")
        self.le_wafer_id.setClearButtonEnabled(True)

        self.lb_product_type = QLabel("Product Type")
        self.lb_product_type.setObjectName("lb_product_type")
        self.le_product_type = QLineEdit()
        self.le_product_type.setText("MCI-23PXX")
        self.le_product_type.setObjectName("le_product_type")
        self.le_product_type.setClearButtonEnabled(True)


        self.le_operator.setFixedWidth(250)
        self.le_machine.setFixedWidth(250)
        self.de_date.setFixedWidth(250)
        self.le_batch_num.setFixedWidth(250)
        # self.le_lot_id.setFixedWidth(250)
        self.le_wafer_id.setFixedWidth(250)
        self.le_product_type.setFixedWidth(250)
        self.fl_test_info.addRow(self.lb_operator, self.le_operator)
        self.fl_test_info.addRow(self.lb_machine, self.le_machine)
        self.fl_test_info.addRow(self.lb_data, self.de_date)
        self.fl_test_info.addRow(self.lb_batch_num, self.le_batch_num)
        # self.fl_test_info.addRow(self.lb_lot_id, self.le_lot_id)
        self.fl_test_info.addRow(self.lb_wafer_id, self.le_wafer_id)
        self.fl_test_info.addRow(self.lb_product_type, self.le_product_type)

        # 测试结果部分
        self.gb_test_result = QGroupBox("设置保存路径")
        self.gb_test_result.setFixedSize(450, 200)
        self.fl_test_result = QFormLayout(self.gb_test_result)
        self.fl_test_result.setVerticalSpacing(10)
        self.fl_test_result.setHorizontalSpacing(20)
        self.lb_spp_proj = QLabel("SPP 工程路径")
        self.lb_spp_proj.setObjectName("lb_spp_proj")
        self.wd_spp_proj = QWidget()
        self.hl_spp_proj = QHBoxLayout(self.wd_spp_proj)
        self.hl_spp_proj.setContentsMargins(0, 0, 0, 0)
        self.le_spp_proj = QLineEdit()
        self.le_spp_proj.setObjectName("le_spp_proj")
        self.pb_spp_proj = QPushButton()
        self.pb_spp_proj.setObjectName("pb_spp_proj")
        self.pb_spp_proj.setMaximumWidth(50)
        self.pb_spp_proj.setIcon(QIcon(OPEN_ICON_PATH))
        self.hl_spp_proj.addWidget(self.le_spp_proj)
        self.hl_spp_proj.addWidget(self.pb_spp_proj)
        self.hl_spp_proj.addStretch(1)
        self.lb_map_path = QLabel("Map 保存路径")
        self.lb_map_path.setObjectName("lb_map_path")
        self.wd_map_path = QWidget()
        self.hl_map_path = QHBoxLayout(self.wd_map_path)
        self.hl_map_path.setContentsMargins(0, 0, 0, 0)
        self.le_map_path = QLineEdit()
        self.le_map_path.setObjectName("le_map_path")
        self.pb_map_path = QPushButton()
        self.pb_map_path.setObjectName("pb_map_path")
        self.pb_map_path.setMaximumWidth(50)
        self.pb_map_path.setIcon(QIcon(OPEN_ICON_PATH))
        self.hl_map_path.addWidget(self.le_map_path)
        self.hl_map_path.addWidget(self.pb_map_path)
        self.hl_map_path.addStretch(1)

        self.lb_file_folder = QLabel("存储文件夹")
        self.lb_file_folder.setObjectName("lb_file_folder")
        self.wd_file_folder = QWidget()
        self.hl_file_folder = QHBoxLayout(self.wd_file_folder)
        self.hl_file_folder.setContentsMargins(0, 0, 0, 0)
        self.le_file_folder = QLineEdit()
        self.le_file_folder.setObjectName("le_file_folder")
        self.pb_file_folder = QPushButton()
        self.pb_file_folder.setObjectName("pb_file_folder")
        self.pb_file_folder.setMaximumWidth(50)
        self.pb_file_folder.setIcon(QIcon(OPEN_ICON_PATH))
        self.hl_file_folder.addWidget(self.le_file_folder)
        self.hl_file_folder.addWidget(self.pb_file_folder)
        self.hl_file_folder.addStretch(1)

        # self.lb_test_batch = QLabel("测试批次号")
        # self.lb_test_batch.setObjectName("lb_test_batch")
        # self.le_test_batch = QLineEdit()
        # self.le_test_batch.setObjectName("le_test_batch")
        # self.le_test_batch.setClearButtonEnabled(True)
        self.le_spp_proj.setEnabled(False)
        self.le_map_path.setEnabled(False)
        self.le_file_folder.setEnabled(False)
        self.le_spp_proj.setFixedWidth(250)
        self.le_map_path.setFixedWidth(250)
        self.le_file_folder.setFixedWidth(250)
        # self.le_test_batch.setFixedWidth(250)
        self.fl_test_result.addRow(self.lb_spp_proj, self.wd_spp_proj)
        self.fl_test_result.addRow(self.lb_map_path, self.wd_map_path)
        self.fl_test_result.addRow(self.lb_file_folder, self.wd_file_folder)
        # 设置温湿度

        # 测试结果部分
        self.gb_other_set = QGroupBox("设置温湿度")
        self.gb_other_set.setFixedSize(450, 200)
        self.fl_other_set = QFormLayout(self.gb_other_set)
        self.fl_other_set.setVerticalSpacing(10)
        # self.fl_other_set.setHorizontalSpacing(20)
        self.lb_waveguide_length = QLabel("波导长度L(cm)")
        self.le_waveguide_length = QLineEdit()
        self.le_waveguide_length.setText("1")
        self.le_waveguide_length.setObjectName("le_waveguide_length")
        self.le_waveguide_length.setClearButtonEnabled(True)

        self.lb_loss_unit = QLabel("单位长度损耗α(dB/cm)")
        self.le_loss_unit = QLineEdit()
        self.le_loss_unit.setText("1")
        self.le_loss_unit.setObjectName("le_loss_unit")
        self.le_loss_unit.setClearButtonEnabled(True)

        self.lb_temperature = QLabel("环境温度(℃)")
        self.le_temperature = QLineEdit()
        self.le_temperature.setText("29")
        self.le_temperature.setObjectName("le_temperature")
        self.le_temperature.setClearButtonEnabled(True)

        self.lb_humidity = QLabel("环境湿度(%rh)")
        self.le_humidity = QLineEdit()
        self.le_humidity.setText("60")
        self.le_humidity.setObjectName("le_humidity")
        self.le_humidity.setClearButtonEnabled(True)

        self.le_waveguide_length.setFixedWidth(250)
        self.le_loss_unit.setFixedWidth(250)
        self.le_temperature.setFixedWidth(250)
        self.le_humidity.setFixedWidth(250)

        self.fl_other_set.addRow(self.lb_temperature, self.le_temperature)
        self.fl_other_set.addRow(self.lb_humidity, self.le_humidity)
        self.fl_other_set.addRow(self.lb_waveguide_length, self.le_waveguide_length)
        self.fl_other_set.addRow(self.lb_loss_unit, self.le_loss_unit)

        self.hl_top.addWidget(self.gb_test_info)
        self.hl_top.addWidget(self.gb_test_result)
        self.hl_top.addWidget(self.gb_other_set)
        self.hl_top.addStretch(1)

        # 全局设置部分
        self.wd_mid = QWidget()
        # self.gb_global_settings = QGroupBox("Global Settings")
        self.hl_global_settings = QHBoxLayout(self.wd_mid)
        self.hl_global_settings.setContentsMargins(0, 0, 0, 0)
        # # TE模对准  O-O
        # self.gb_oo_settings = QGroupBox("TE模对准O-O设置")
        # self.gl_oo_settings = QGridLayout(self.gb_oo_settings)
        # self.gb_oo_settings.setContentsMargins(0, 0, 0, 0)
        #
        # self.lb_oo_8164 = QLabel("8164B:")
        # self.lb_oo_8164.setObjectName("lb_oo_8164")
        # self.wd_oo_8164_power = QWidget()
        # self.hl_oo_8164_power = QHBoxLayout(self.wd_oo_8164_power)
        # self.hl_oo_8164_power.setContentsMargins(0, 0, 0, 0)
        # self.lb_oo_8164_power = QLabel("功率设置：")
        # self.le_oo_8164_power = QLineEdit()
        # self.le_oo_8164_power.setClearButtonEnabled(True)
        # self.cb_oo_8164_power = QComboBox()
        # self.cb_oo_8164_power.addItems(['dBm'])
        # self.hl_oo_8164_power.addWidget(self.lb_oo_8164_power)
        # self.hl_oo_8164_power.addWidget(self.le_oo_8164_power)
        # self.hl_oo_8164_power.addWidget(self.cb_oo_8164_power)
        # self.hl_oo_8164_power.addStretch(1)
        #
        # self.wd_oo_8164_wave = QWidget()
        # self.hl_oo_8164_wave = QHBoxLayout(self.wd_oo_8164_wave)
        # self.hl_oo_8164_wave.setContentsMargins(0, 0, 0, 0)
        # self.lb_oo_8164_wave = QLabel("波长设置：")
        # self.le_oo_8164_wave = QLineEdit()
        # self.le_oo_8164_wave.setClearButtonEnabled(True)
        # self.cb_oo_8164_wave = QComboBox()
        # self.cb_oo_8164_wave.addItems(['nm'])
        # self.hl_oo_8164_wave.addWidget(self.lb_oo_8164_wave)
        # self.hl_oo_8164_wave.addWidget(self.le_oo_8164_wave)
        # self.hl_oo_8164_wave.addWidget(self.cb_oo_8164_wave)
        # self.hl_oo_8164_wave.addStretch(1)
        #
        # self.lb_oo_7744 = QLabel("7744C:")
        # self.wd_oo_7744_range = QWidget()
        # self.hl_oo_7744_range = QHBoxLayout(self.wd_oo_7744_range)
        # self.hl_oo_7744_range.setContentsMargins(0, 0, 0, 0)
        # self.lb_oo_7744_range = QLabel("量程设置：")
        # self.cb_oo_7744_range = QComboBox()
        # self.cb_oo_7744_range.addItems(constant.N7744_RAGNE)
        # self.hl_oo_7744_range.addWidget(self.lb_oo_7744_range)
        # self.hl_oo_7744_range.addWidget(self.cb_oo_7744_range)
        # self.hl_oo_7744_range.addStretch(1)
        #
        # self.gl_oo_settings.addWidget(self.lb_oo_8164, 0, 0)
        # self.gl_oo_settings.addWidget(self.wd_oo_8164_power, 0, 1)
        # self.gl_oo_settings.addWidget(self.wd_oo_8164_wave, 1, 1)
        # self.gl_oo_settings.addWidget(self.lb_oo_7744, 4, 0)
        # self.gl_oo_settings.addWidget(self.wd_oo_7744_range, 4, 1)
        #
        # # TE模对准  O-E
        # self.gb_oe_settings = QGroupBox("TE模对准O-E设置")
        # self.gl_oe_settings = QGridLayout(self.gb_oe_settings)
        # self.gb_oe_settings.setContentsMargins(0, 0, 0, 0)
        #
        # self.lb_oe_8164 = QLabel("8164B:")
        # self.wd_oe_8164_power = QWidget()
        # self.hl_oe_8164_power = QHBoxLayout(self.wd_oe_8164_power)
        # self.hl_oe_8164_power.setContentsMargins(0, 0, 0, 0)
        # self.lb_oe_8164_power = QLabel("功率设置：")
        # self.le_oe_8164_power = QLineEdit()
        # self.le_oe_8164_power.setClearButtonEnabled(True)
        # self.cb_oe_8164_power = QComboBox()
        # self.cb_oe_8164_power.addItems(['dBm'])
        # self.hl_oe_8164_power.addWidget(self.lb_oe_8164_power)
        # self.hl_oe_8164_power.addWidget(self.le_oe_8164_power)
        # self.hl_oe_8164_power.addWidget(self.cb_oe_8164_power)
        # self.hl_oe_8164_power.addStretch(1)
        #
        # self.wd_oe_8164_wave = QWidget()
        # self.hl_oe_8164_wave = QHBoxLayout(self.wd_oe_8164_wave)
        # self.hl_oe_8164_wave.setContentsMargins(0, 0, 0, 0)
        # self.lb_oe_8164_wave = QLabel("波长设置：")
        # self.le_oe_8164_wave = QLineEdit()
        # self.le_oe_8164_wave.setClearButtonEnabled(True)
        # self.cb_oe_8164_wave = QComboBox()
        # self.cb_oe_8164_wave.addItems(['nm'])
        # self.hl_oe_8164_wave.addWidget(self.lb_oe_8164_wave)
        # self.hl_oe_8164_wave.addWidget(self.le_oe_8164_wave)
        # self.hl_oe_8164_wave.addWidget(self.cb_oe_8164_wave)
        # self.hl_oe_8164_wave.addStretch(1)
        #
        # self.lb_oe_source = QLabel("源表：")
        # self.wd_oe_source_offset = QWidget()
        # self.hl_oe_source_offset = QHBoxLayout(self.wd_oe_source_offset)
        # self.hl_oe_source_offset.setContentsMargins(0, 0, 0, 0)
        # self.lb_oe_source_offset = QLabel("偏置电压：")
        # self.le_oe_source_offset = QLineEdit()
        # self.le_oe_source_offset.setClearButtonEnabled(True)
        # self.cb_oe_source_offset = QComboBox()
        # self.cb_oe_source_offset.addItems(["mV", "V"])
        # self.hl_oe_source_offset.addWidget(self.lb_oe_source_offset)
        # self.hl_oe_source_offset.addWidget(self.le_oe_source_offset)
        # self.hl_oe_source_offset.addWidget(self.cb_oe_source_offset)
        # self.hl_oe_source_offset.addStretch(1)
        #
        # self.wd_oe_source_range = QWidget()
        # self.hl_oe_source_range = QHBoxLayout(self.wd_oe_source_range)
        # self.hl_oe_source_range.setContentsMargins(0, 0, 0, 0)
        #
        # self.lb_oe_source_range = QLabel("量程设置：")
        # self.cb_oe_source_range = QComboBox()
        # self.cb_oe_source_range.addItems(["Auto"])
        # self.cb_oe_source_range.setEnabled(False)
        # self.hl_oe_source_range.addWidget(self.lb_oe_source_range)
        # self.hl_oe_source_range.addWidget(self.cb_oe_source_range)
        # self.hl_oe_source_range.addStretch(1)
        #
        # self.wd_oe_source_speed = QWidget()
        # self.hl_oe_source_speed = QHBoxLayout(self.wd_oe_source_speed)
        # self.hl_oe_source_speed.setContentsMargins(0, 0, 0, 0)
        # self.lb_oe_source_speed = QLabel("积分时间：")
        # self.cb_oe_source_speed = QComboBox()
        # self.cb_oe_source_speed.addItems(["1PLC"])
        # self.cb_oe_source_speed.setEnabled(False)
        # self.hl_oe_source_speed.addWidget(self.lb_oe_source_speed)
        # self.hl_oe_source_speed.addWidget(self.cb_oe_source_speed)
        # self.hl_oe_source_speed.addStretch(1)
        #
        # self.gl_oe_settings.addWidget(self.lb_oe_8164, 0, 0)
        # self.gl_oe_settings.addWidget(self.wd_oe_8164_power, 0, 1)
        # self.gl_oe_settings.addWidget(self.wd_oe_8164_wave, 1, 1)
        # self.gl_oe_settings.addWidget(self.lb_oe_source, 4, 0)
        # self.gl_oe_settings.addWidget(self.wd_oe_source_offset, 4, 1)
        # self.gl_oe_settings.addWidget(self.wd_oe_source_range, 5, 1)
        # self.gl_oe_settings.addWidget(self.wd_oe_source_speed, 6, 1)

        # 链路损耗校准
        self.gb_lc_settings = QGroupBox("链路损耗校准设置")
        self.gb_lc_settings.setFixedSize(600, 250)
        self.gl_lc_settings = QGridLayout(self.gb_lc_settings)
        self.gb_lc_settings.setContentsMargins(0, 0, 0, 0)
        self.gl_lc_settings.setVerticalSpacing(2)

        self.bg_group = QButtonGroup(self.gl_lc_settings)
        self.hl_voltage = QHBoxLayout()
        self.rb_loss_sys = QRadioButton()
        self.rb_loss_sys.setText("loss_sys")
        self.rb_loss_sys.setObjectName("rb_loss_sys")
        self.rb_loss_sys.setChecked(True)
        self.rb_pd_loss_sys = QRadioButton()
        self.rb_pd_loss_sys.setText("pd_loss_sys")
        self.rb_pd_loss_sys.setObjectName("rb_pd_loss_sys")

        self.hl_voltage.addWidget(self.rb_loss_sys)
        self.hl_voltage.addWidget(self.rb_pd_loss_sys)
        self.bg_group.addButton(self.rb_loss_sys, 1)
        self.bg_group.addButton(self.rb_pd_loss_sys, 2)

        self.lb_lc_8164 = QLabel("8164B:")
        self.wd_lc_8164_power = QWidget()
        self.hl_lc_8164_power = QHBoxLayout(self.wd_lc_8164_power)
        self.hl_lc_8164_power.setContentsMargins(0, 0, 0, 0)
        self.lb_lc_8164_power = QLabel("功率设置：")
        self.le_lc_8164_power = QLineEdit()
        self.le_lc_8164_power.setText("10")
        self.le_lc_8164_power.setObjectName("le_lc_8164_power")
        self.le_lc_8164_power.setClearButtonEnabled(True)
        self.cb_lc_8164_power = QComboBox()
        self.cb_lc_8164_power.setObjectName("cb_lc_8164_power")
        self.cb_lc_8164_power.addItems(['dBm'])
        self.hl_lc_8164_power.addWidget(self.lb_lc_8164_power)
        self.hl_lc_8164_power.addWidget(self.le_lc_8164_power)
        self.hl_lc_8164_power.addWidget(self.cb_lc_8164_power)
        self.hl_lc_8164_power.addStretch(1)

        self.wd_lc_8164_step = QWidget()
        self.hl_lc_8164_step = QHBoxLayout(self.wd_lc_8164_step)
        self.hl_lc_8164_step.setContentsMargins(0, 0, 0, 0)
        self.lb_lc_8164_step = QLabel("步进设置：")
        self.le_lc_8164_step = QLineEdit()
        self.le_lc_8164_step.setText("1")
        self.le_lc_8164_step.setObjectName("le_lc_8164_step")
        self.le_lc_8164_step.setClearButtonEnabled(True)
        self.cb_lc_8164_step = QComboBox()
        self.cb_lc_8164_step.setObjectName("cb_lc_8164_step")
        self.cb_lc_8164_step.addItems(['nm'])
        self.hl_lc_8164_step.addWidget(self.lb_lc_8164_step)
        self.hl_lc_8164_step.addWidget(self.le_lc_8164_step)
        self.hl_lc_8164_step.addWidget(self.cb_lc_8164_step)
        self.hl_lc_8164_step.addStretch(1)

        self.wd_lc_8164_wave = QWidget()
        self.hl_lc_8164_wave = QHBoxLayout(self.wd_lc_8164_wave)
        self.hl_lc_8164_wave.setContentsMargins(0, 0, 0, 0)
        self.lb_lc_8164_wave = QLabel("波长设置：")
        self.le_lc_8164_wave_start = QLineEdit()
        self.le_lc_8164_wave_start.setText("1260")
        self.le_lc_8164_wave_start.setObjectName("le_lc_8164_wave_start")
        self.le_lc_8164_wave_stop = QLineEdit()
        self.le_lc_8164_wave_stop.setText("1360")
        self.le_lc_8164_wave_stop.setObjectName("le_lc_8164_wave_stop")
        self.cb_lc_8164_wave = QComboBox()
        self.cb_lc_8164_wave.setObjectName("cb_lc_8164_wave")
        self.cb_lc_8164_wave.addItems(['nm'])
        self.hl_lc_8164_wave.addWidget(self.lb_lc_8164_wave)
        self.hl_lc_8164_wave.addWidget(self.le_lc_8164_wave_start)
        self.hl_lc_8164_wave.addWidget(QLabel("~"))
        self.hl_lc_8164_wave.addWidget(self.le_lc_8164_wave_stop)
        self.hl_lc_8164_wave.addWidget(self.cb_lc_8164_wave)
        self.hl_lc_8164_wave.addStretch(1)

        self.wd_lc_7744_range = QWidget()
        self.hl_lc_7744_range = QHBoxLayout(self.wd_lc_7744_range)
        self.hl_lc_7744_range.setContentsMargins(0, 0, 0, 0)
        self.lb_lc_7744 = QLabel("7744C:")
        self.lb_lc_7744_range = QLabel("量程设置：")
        self.cb_lc_7744_range = QComboBox()
        self.cb_lc_7744_range.setObjectName("cb_lc_7744_range")
        self.cb_lc_7744_range.addItems(constant.N7744_RAGNE)
        self.pb_lc_test = QPushButton("测试")
        self.pb_lc_test.setObjectName("pb_lc_test")
        self.pb_lc_test.setFixedWidth(100)
        self.hl_lc_7744_range.addWidget(self.lb_lc_7744_range)
        self.hl_lc_7744_range.addWidget(self.cb_lc_7744_range)
        self.hl_lc_7744_range.addWidget(self.pb_lc_test)
        self.hl_lc_7744_range.addStretch(1)

        self.gl_lc_settings.addWidget(self.rb_loss_sys, 0, 0)
        self.gl_lc_settings.addWidget(self.rb_pd_loss_sys, 0, 1)
        self.gl_lc_settings.addWidget(self.lb_lc_8164, 1, 0)
        self.gl_lc_settings.addWidget(self.wd_lc_8164_power, 1, 1)
        self.gl_lc_settings.addWidget(self.wd_lc_8164_step, 2, 1)
        self.gl_lc_settings.addWidget(self.wd_lc_8164_wave, 3, 1, 1, 3, Qt.AlignLeft | Qt.AlignVCenter)
        self.gl_lc_settings.addWidget(self.lb_lc_7744, 4, 0)
        self.gl_lc_settings.addWidget(self.wd_lc_7744_range, 4, 1)

        # 设置探针的移动顺序
        self.gb_probe_settings = QGroupBox("设置探针的移动顺序")
        self.gb_probe_settings.setFixedSize(300, 250)
        self.gb_probe_settings.setObjectName("gb_probe_settings")
        self.gb_probe_settings.setContentsMargins(0, 0, 0, 0)
        self.gl_probe_settings = QGridLayout(self.gb_probe_settings)
        self.gl_probe_settings.setContentsMargins(30, 10, 30, 10)
        self.gl_probe_settings.setHorizontalSpacing(30)
        #
        sequcene = ['H1', 'H2', 'P1', 'P2']
        self.lb_probe_first = QLabel("第一个移动探针编号:")
        self.cb_probe_first = QComboBox()
        self.cb_probe_first.setObjectName("cb_probe_first")
        self.cb_probe_first.addItems(sequcene)
        self.cb_probe_first.setCurrentIndex(2)

        self.lb_probe_second = QLabel("第二个移动探针编号:")
        self.cb_probe_second = QComboBox()
        self.cb_probe_second.setObjectName("cb_probe_second")
        self.cb_probe_second.addItems(sequcene)
        self.cb_probe_second.setCurrentIndex(3)

        self.lb_probe_third = QLabel("第三个移动探针编号:")
        self.cb_probe_third = QComboBox()
        self.cb_probe_third.setObjectName("cb_probe_third")
        self.cb_probe_third.addItems(sequcene)
        self.cb_probe_third.setCurrentIndex(1)

        self.lb_probe_four = QLabel("第四个移动探针编号:")
        self.cb_probe_four = QComboBox()
        self.cb_probe_four.setObjectName("cb_probe_four")
        self.cb_probe_four.addItems(sequcene)
        self.cb_probe_four.setCurrentIndex(0)

        self.btn_probe_ensure = QPushButton("确认探针移动顺序")
        self.btn_probe_ensure.setObjectName("btn_probe_ensure")

        self.gl_probe_settings.addWidget(self.lb_probe_first, 0, 0)
        self.gl_probe_settings.addWidget(self.cb_probe_first, 0, 1)
        self.gl_probe_settings.addWidget(self.lb_probe_second, 1, 0)
        self.gl_probe_settings.addWidget(self.cb_probe_second, 1, 1)
        self.gl_probe_settings.addWidget(self.lb_probe_third, 2, 0)
        self.gl_probe_settings.addWidget(self.cb_probe_third, 2, 1)
        self.gl_probe_settings.addWidget(self.lb_probe_four, 3, 0)
        self.gl_probe_settings.addWidget(self.cb_probe_four, 3, 1)
        self.gl_probe_settings.addWidget(self.btn_probe_ensure, 4, 0, 1, 2)

        # self.le_oo_8164_wave.setFixedWidth(LE_LENGTH)
        # self.le_oo_8164_power.setFixedWidth(LE_LENGTH)
        # self.le_oe_8164_wave.setFixedWidth(LE_LENGTH)
        # self.le_oe_8164_power.setFixedWidth(LE_LENGTH)
        # self.le_oe_source_offset.setFixedWidth(LE_LENGTH)
        # self.le_lc_8164_step.setFixedWidth(LE_LENGTH)
        # self.le_lc_8164_power.setFixedWidth(LE_LENGTH)
        # self.le_lc_8164_wave_start.setFixedWidth(70)
        # self.le_lc_8164_wave_stop.setFixedWidth(70)
        # self.cb_oo_8164_wave.setFixedWidth(UNIT_LENGTH)
        # self.cb_oo_7744_range.setFixedWidth(LE_LENGTH)
        # self.cb_oo_8164_power.setFixedWidth(UNIT_LENGTH)
        # self.cb_oe_8164_wave.setFixedWidth(UNIT_LENGTH)
        # self.cb_oe_8164_power.setFixedWidth(UNIT_LENGTH)
        # self.cb_oe_source_offset.setFixedWidth(UNIT_LENGTH)
        # self.cb_oe_source_speed.setFixedWidth(LE_LENGTH)
        # self.cb_oe_source_range.setFixedWidth(LE_LENGTH)
        # self.cb_lc_8164_step.setFixedWidth(UNIT_LENGTH)
        # self.cb_lc_8164_wave.setFixedWidth(UNIT_LENGTH)
        # self.cb_lc_8164_power.setFixedWidth(UNIT_LENGTH)
        # self.cb_lc_7744_range.setFixedWidth(LE_LENGTH)
        #
        # self.hl_global_settings.addWidget(self.gb_oo_settings)
        self.hl_global_settings.addWidget(self.gb_lc_settings)
        self.hl_global_settings.addWidget(self.gb_probe_settings)
        self.hl_global_settings.addItem(QSpacerItem(20, 40, QSizePolicy.Expanding, QSizePolicy.Expanding))

        # 测试区域
        self.gb_test_area = QGroupBox("测试工程设置")
        self.gb_test_area.setFixedSize(1350, 380)
        self.hl_test_area = QHBoxLayout(self.gb_test_area)
        self.hl_test_area.setContentsMargins(0, 0, 10, 0)
        self.vl_label_listWidget = QVBoxLayout()
        self.vl_label_listWidget.setContentsMargins(0, 0, 10, 0)
        self.w_head = QWidget()
        self.gl_head = QGridLayout(self.w_head)

        labelStytle = "color:white;background:gray;border-width:0;"
        self.w_head.setStyleSheet(labelStytle)
        self.gl_head.addWidget(QLabel("Subdie ID"), 0, 0)
        self.gl_head.addWidget(QLabel("测试工程"), 0, 1)
        self.gl_head.addWidget(QLabel("工程SetUp"), 0, 2)
        self.gl_head.setHorizontalSpacing(160)
        self.gl_head.setColumnStretch(3, 1)

        self.lw_test_area = QListWidget()
        self.lw_test_area.setObjectName("lw_test_area")
        # self.lw_test_area.setFixedWidth(1200)
        self.vl_label_listWidget.addWidget(self.w_head)
        self.vl_label_listWidget.addWidget(self.lw_test_area)

        self.hl_test_area.addLayout(self.vl_label_listWidget)
        self.vl_btn_handler = QVBoxLayout()
        self.vl_btn_handler.setContentsMargins(10, 0, 10, 10)
        self.l_handle = QLabel("操作")
        self.l_handle.setFixedSize(140,43)
        self.l_handle.setStyleSheet(labelStytle)
        self.l_handle.setAlignment(Qt.AlignCenter)
        self.btn_add_item = QPushButton("增加一行")
        # self.btn_add_item.setFixedWidth(100)
        self.btn_add_item.setObjectName("btn_add_item")

        self.btn_delete_item = QPushButton("删除一行")
        # self.btn_delete_item.setFixedWidth(100)
        self.btn_delete_item.setObjectName("btn_delete_item")
        # self.btn_delete_item.hide()
        self.vl_btn_handler.addWidget(self.l_handle)
        self.vl_btn_handler.addWidget(self.btn_add_item)
        self.vl_btn_handler.addWidget(self.btn_delete_item)
        self.vl_btn_handler.addStretch(1)
        self.hl_test_area.addLayout(self.vl_btn_handler)
        # self.hl_test_area.addStretch(1)

        # 设置主界面
        self.vl_main.addWidget(self.wd_top)
        self.vl_main.addWidget(self.wd_mid)
        self.vl_main.addWidget(self.gb_test_area)
        self.setCentralWidget(self.wd_main)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Gui()
    window.show()
    sys.exit(app.exec())
